'''
警告弹窗的常用方法：
(1)switch_to_alert().accept()
(2)switch_to.alert.accept()	建议这个
'''
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC  # 起个别名
from time import sleep
from options import options
from service import service

dr=webdriver.Chrome(options=options,service=service)
dr.get(r'https://www.baidu.com/')
dr.maximize_window()

# 鼠标悬停在设置上
ele=dr.find_element(By.ID,'s-usersetting-top')
ActionChains(dr).move_to_element(ele).perform()
sleep(3)
dr.find_element(By.LINK_TEXT,'搜索设置').click()
sleep(1)
dr.find_element(By.LINK_TEXT,'保存设置').click()
sleep(1)
# 处理警告弹窗
# 获取本文
text=dr.switch_to.alert.text
print(text)
sleep(3)
# 点击确定
dr.switch_to.alert.accept()
sleep(3)